package cn.com.xinjinfu.pdoulcProduct.manager;

import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.com.xinjinfu.pdoulcProduct.R;

/**
 * Created by android-adt on 2015/12/29.
 * title 管理
 */
public class TitleManager {
    public boolean color = false;//
    public boolean left = false;//
    /**
     *
     * @param from
     *            当前的界面
     * @param title
     *            title正中需要显示的文本
     * @param right
     *            title右边需要显示的文本资源
     */
    public static void showTitle(final Activity from,String title, boolean color, String right,boolean left) {
        TextView tv_title = (TextView) from.findViewById(R.id.top_title_tv);
        try {
            if (color) {
                tv_title.setTextColor(0xffffffff);     //color为true时，字体设置成白色
                tv_title.setText(title);
            }
            tv_title.setText(title);
        } catch (Exception e) {
            e.printStackTrace();
        }
            LinearLayout ll = (LinearLayout) from
                    .findViewById(R.id.top_right_ll);
            ll.setVisibility(View.VISIBLE);
            TextView tv = (TextView) from.findViewById(R.id.top_right_tv);
            if (color) {
                tv.setTextColor(0xffffffff);     //color为true时，字体设置成白色
                tv.setText(right);
            }
            tv.setText(right);
        if (left) {          //left为true时返回图标为白色
            LinearLayout top_left_ll= (LinearLayout) from.findViewById(R.id.top_left_ll);
            top_left_ll.setVisibility(View.VISIBLE);
            top_left_ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    from.onBackPressed();
                }
            });
            ImageView mTopLeft= (ImageView) from.findViewById(R.id.top_left_icon0);
            mTopLeft.setImageResource(R.drawable.img_angle2);

        }else {
            LinearLayout top_left_ll= (LinearLayout) from.findViewById(R.id.top_left_ll);
            top_left_ll.setVisibility(View.VISIBLE);
            top_left_ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    from.onBackPressed();
                }
            });
            ImageView mTopLeft= (ImageView) from.findViewById(R.id.top_left_icon0);
            mTopLeft.setImageResource(R.drawable.img_angle1);
        }
    }

    /**
     * 字体为黑色时直接调用此方法即可
     * @param activity
     * @param title
     * @param right
     */
    public static void showTitle(final Activity activity, String title,String right) {
        showTitle(activity, title, false, right, false);
    }
    /**
     * 字体为白色时直接调用此方法即可
     * @param activity
     * @param title
     * @param right
     */
    public static void showTitleWhite(final Activity activity, String title,String right) {
        showTitle(activity, title, true, right, true);
    }
    /**
     * 字体为白色  只显示中间标题，没有返回键
     * @param activity
     * @param title
     */
    public static void showcentreTitle(final Activity activity, String title) {
        showTitle(activity, title, true, "", true);
        LinearLayout top_left_ll= (LinearLayout) activity.findViewById(R.id.top_left_ll);
        top_left_ll.setVisibility(View.GONE);
    }


}
